package star.基础.两数之和;

import star.Utils;

import java.util.HashMap;

public class TwoSum {
    public static void main(String[] args) {
        int[] arr = {3,2,4};
        int[] twoSum = new TwoSum().twoSum(arr, 6);
        Utils.traversal(twoSum);
    }
    public int[] twoSum(int[] nums,int target){
        if(nums==null || nums.length < 1) return null;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; ++i) {
            if (map.containsKey(target - nums[i])) {
                return new int[]{map.get(target - nums[i]), i};
            }
            map.put(nums[i], i);
        }
        return new int[0];
    }
}